#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool isLeap(int year)
{
	if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) return true;
	return false;
}
int Month[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
int y, d, mon = 1;

int main() {
	cin >> y >> d;

	bool isLeapYear = isLeap(y); // 是否为闰年
	for (int i = 0; i < 12; i++)
	{
		if (i == 1 && isLeapYear)
		{
			d -= 29;
		}
		else
		{
			d -= Month[i];
		}
		
		if (d <= 0)
		{
			if (i == 1 && isLeapYear) 
			{
				cout << mon << endl << d + 29;
			}
			else
			{
				cout << mon << endl << d + Month[i];
			}			
			break;
		}
		else
		{
			mon++;
		}
	}

	return 0;
}
